/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Resultados.java
 *
 * Created on 08-oct-2011, 22:36:07
 */
package Principal.regresion;

import java.awt.FlowLayout;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import librerias.regresion.EscalaMovil;
import librerias.regresion.ListaDobleConOrden;
import librerias.regresion.NodoDoble;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;

/**
 *
 * @author JONATHAN
 */
public class Resultados extends javax.swing.JFrame {

    public DefaultTableModel miModelo;
    public String[][] data = {};

    JTable getMiTabla() {
        return Tabla_1;
    }

    public DefaultTableModel getMiModelo() {
        return miModelo;
    }

    /** Creates new form Resultados */
    Resultados(JFreeChart chart, ListaDobleConOrden ldco) {
        initComponents();
        setLocationRelativeTo(null);
        // Hacemos y mostramos una ventana con el último de ellos
        ChartPanel grafico = new ChartPanel(chart);
        jPanel1.setLayout(new FlowLayout());
        jPanel1.add(grafico);
        jPanel1.updateUI();

        miModelo = new DefaultTableModel(data, new String[]{"Periodo", "Y", "Y_y", "EM","Limite Superior","Limite Inferior"}) {
        };
        Tabla_1.setModel(miModelo);
        jScrollPane1.setViewportView(Tabla_1);

        Llenar_Tabla(ldco);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        Tabla_1 = new javax.swing.JTable();
        jScrollPane2 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Resultados");

        Tabla_1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Periodo", "Y", "y", "Y_y", "EM"
            }
        ));
        jScrollPane1.setViewportView(Tabla_1);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 461, Short.MAX_VALUE)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 373, Short.MAX_VALUE)
        );

        jScrollPane2.setViewportView(jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 345, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 463, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 375, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable Tabla_1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    // End of variables declaration//GEN-END:variables

    private void Llenar_Tabla(ListaDobleConOrden ldco) {
        inicializaTabla();
        NodoDoble auxiliar;
        auxiliar = ldco.getInicio();
        while (auxiliar != null) {
            EscalaMovil dir = auxiliar.getNodo();
            Object[] datos = {dir.getPeriodo(), dir.getVar_Y(), dir.getVarY_y(), dir.getEM(), dir.getLimite_S(),dir.getLimite_I()};
            getMiModelo().addRow(datos);
            //retrocede al nodo anterior
            auxiliar = auxiliar.getApuntSgte();
        }
    }

    private void inicializaTabla() {
        // obtiene numero de filas de la tabla
        int filas = getMiTabla().getRowCount();
        // remueve todas las filas de la tabla
        for (int fila = 0; fila < filas; fila++) {
            getMiModelo().removeRow(0);
        }
    }
}
